﻿using SharpDepend;
using System;
using ZquenceStudio3Host.Graphics.Components;
using ZquenceStudio3Host.Graphics.GUI;

namespace DefaultDspPlugins.UI.Common.Modulizer.Engine.GUI
{
    public class ModulizerUIPanel : Panel
    {
        public ModulizerUIPanel(BasicGuiManager engineCore) : base(engineCore)
        {
        }

        public Panel Content { get; set; }

        public override void Render(IGraphicsDevice canvas, Parent parent)
        {
            Panel content = Content;
            if (content != null)
            {
                if (!content.DimensionInProcent)
                {
                    throw new Exception("Content in ModulizerUIPanel do not support non-dimeansion in percent");
                }

                // Update position and scale.
                double scaleUp = 0;
                if (content.Width - RealWidth < content.Height - RealHeight)
                {
                    scaleUp = RealWidth / content.Width;
                }
                else
                {
                    scaleUp = RealHeight / content.Height;
                }
                
                double tempWidth = content.Width;
                double tempHeight = content.Height;

                content.Width *= scaleUp;
                content.Height *= scaleUp;

                base.Render(canvas, parent);

                content.Width = tempWidth;
                content.Height = tempHeight;
            }
            else
            {
                base.Render(canvas, parent);
            }
        }
    }
}
